use std::slice;

static mut APP_NAME: &str = "rust-web";
fn main() {
    let mut name = "hboot";

    let name_1 = &name as *const &str;

    let name_2 = &mut name as *mut &str;

    unsafe {
        println!("{:?}", *name_1);
        *name_2 = "hello";
        println!("{:?}", *name_2);
        println!("{:?}", *name_1);
    }

    unsafe {
        get_name();
    }

    let mut arr = [1, 2, 3, 4, 5];

    println!("{:?}", split_arr(&mut arr, 3));

    // unsafe { print!("{}", find(45)) }

    unsafe {
        println!("{}", APP_NAME);
        APP_NAME = "hboot";
        println!("{}", APP_NAME);
    }
}

unsafe fn get_name() {}
fn split_arr(arr: &mut [i32], t_index: usize) -> (&mut [i32], &mut [i32]) {
    let len = arr.len();
    let temp = arr.as_mut_ptr();

    unsafe {
        (
            slice::from_raw_parts_mut(temp, t_index),
            slice::from_raw_parts_mut(temp.add(t_index), len - t_index),
        )
    }
}

fn return_arr() -> ([i32; 2], [i32; 2]) {
    let arr1 = [12, 3];
    let arr2 = [23, 5];
    (arr1, arr2)
}

extern "C" {
    fn find(age: i32) -> i32;
}

#[no_mangle]
pub extern "C" fn find_name() {
    println!("hello,call this in other ")
}

trait Log {
    unsafe fn entry_log(&self) -> &str {
        let msg = String::from("entry log...");

        let str = &msg as *const String;

        &*str
    }
}
